package com.fzu.express.mapper;

import com.fzu.express.entity.Outlet;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zyq
 * @since 2022-10-27
 */
public interface OutletMapper extends BaseMapper<Outlet> {

    /**
     * 获取与该经纬度最近的地址
     * @param lng 经度
     * @param lat 纬度
     * @return Outlet
     */
    @Select("select * from express_outlet as eo " +
            "where eo.deleted = 0 and eo.status = 1 and eo.province = #{province} and eo.city = #{city} " +
            "and exists (select wu.id from web_user as wu where wu.role = 1 and wu.outlet_id = eo.id) " +
            "order by st_distance(POINT(eo.longitude , eo.latitude), POINT(#{lng} , #{lat}))*111195 limit 1")
    Outlet selectNearestOutlet(@Param("lng")Double lng, @Param("lat") Double lat,
                               @Param("province") String province, @Param("city") String city);

}
